﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;

namespace FrontEndPlus.Módulos.Seguridad
{
    public class cls_Ftp_Remote_Upload : cls_Remote_Upload
    {
        public cls_Ftp_Remote_Upload(byte[] fileData, string fileNamePath, string urlString, string usuario, string password)
            : base(fileData, fileNamePath, urlString, usuario, password)
        {

        }

        public override bool UploadFile()
        {
            try
            {
                FtpWebRequest reqFTP = (FtpWebRequest)FtpWebRequest.Create(this.UrlString);
                reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
                reqFTP.Credentials = new NetworkCredential(Usuario, Password);
                reqFTP.UsePassive = true;
                reqFTP.UseBinary = true;
                reqFTP.KeepAlive = true;

                byte[] buff = new byte[0];
                MemoryStream streamNuevo = new MemoryStream(this.FileData);
                Stream reqStream = reqFTP.GetRequestStream();
                reqStream.Write(FileData, 0, FileData.Length);
                reqStream.Flush();
                reqStream.Close();
                return true;
            }
            catch (Exception ex)
            {
                Console.Write("Failed to upload", ex.InnerException);
                return false;
            }
        }
    }
}